let mysqlModule = require("mysql");
let connection = null;
class mysql {

    query(sql, value) {

        let promise = new Promise(function (resolve, reject) {

            let connection = mysqlModule.createConnection({ host: '127.0.0.1', user: 'root', password: '123456', database: 'yiqing' });
            connection.connect();
            connection.query(sql, value, function (err, result) {

                if (err) {
                    console.log(err.message);
                    //reject(err.message)
                } else {
                    //setTimeout(function () {//模拟数据的慢查询
                        resolve(result);
                    //},5000)
                }
                connection.end();
            })

        })
        return promise;
    }
}

module.exports = mysql;